﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace 环境变量
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var configBuilder = new ConfigurationBuilder();
            configBuilder.AddEnvironmentVariables("conf_");
            var config = configBuilder.Build();

            var services = new ServiceCollection();
            services.AddSingleton<IConfiguration>(config);
            //services.AddOptions();
            services.Configure<Person>(config);
            //services.AddOptions<Person>().Configure<IConfiguration>((per, config) =>
            //{
            //    config.Bind(per);
            //});

            services.AddTransient<TestService>();
            using (var sp = services.BuildServiceProvider())
            {
                var service = sp.GetRequiredService<TestService>();
                service.Show();
            }

            Console.ReadKey();
        }
    }
}